LARAVEL FOR BEGINNERS: Learn Coding Fast: LARAVEL PHP WEB Framework, Quick Start E book, Tutorial book with Hands-On Projects in Easy steps, An ultimate Beginner's guide by SEL TAM
Author:SEL, TAM [SEL, TAM]
Language: eng
Format: epub
Published: 2020-04-15T16:00:00+00:00
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull:: class ,
];
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies:: class ,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse:: class ,
\Illuminate\Session\Middleware\StartSession:: class ,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware \ShareErrorsFromSession:: class ,
\App\Http\Middleware\VerifyCsrfToken:: class ,
\Illuminate\Routing\Middleware\SubstituteBindings:: class ,
],
'api' => [
'throttle:60,1',
'bindings',
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
*
@var array
*/
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate:: class ,
'auth.basic' => \Illuminate\Auth\Middleware
\AuthenticateWithBasicAuth:: class ,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings:: class ,
'can' => \Illuminate\Auth\Middleware\Authorize:: class ,
'guest' => \App\Http\Middleware
\RedirectIfAuthenticated:: class ,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests:: class ,
'age' => \App\Http\Middleware\CheckAge:: class ];
}
In the above code, we have added the code, i.e., ''age' => \App\Http\Middleware\CheckAge::class' , where age is the name of the middleware. Now, we can use the 'age' middleware for some specific routes.
Step 2: Open the CheckAge.php file, which you have created as a middleware.
Step 3: Add the middleware code in the web.php file.
Route::Get('/', function ()
{
return view('welcome');
})-> middleware('age');
Route::Get('user/profile', function ()
{
return "user profile";
});
In the above code, we have added middleware in '/' root URL, and we have not added the middleware in the 'user/profile' URL.
When the parameter is passed in a URL.
web.php
Route::Get('/{age}', function ($age)
{
return view('welcome');
})-> middleware('age');
CheckAge.php
<?php
namespace App\Http\Middleware;
use Closure;
class CheckAge
{
/**
* Handle an incoming request.
*
* @param
\Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
//return "middleware";
echo "this is checkage middleware";
return $next($request);
}}
Check condition in middleware
Middleware can also be used to check the condition. Let's understand through an example.
Route::Get('/{age}', function ($age)
{
return view('welcome');
})-> middleware('age');
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(22431)
Hello! Python by Anthony Briggs(21619)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(20183)
Dependency Injection in .NET by Mark Seemann(19563)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(19309)
Kotlin in Action by Dmitry Jemerov(19231)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(18772)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(17575)
Adobe Camera Raw For Digital Photographers Only by Rob Sheppard(16960)
Grails in Action by Glen Smith Peter Ledbrook(16726)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(10922)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(8064)
Microservices with Go by Alexander Shuiskov(7829)
Practical Design Patterns for Java Developers by Miroslav Wengner(7731)
Test Automation Engineering Handbook by Manikandan Sambamurthy(7689)
Angular Projects - Third Edition by Aristeidis Bampakos(7176)
The Art of Crafting User Stories by The Art of Crafting User Stories(6622)
NetSuite for Consultants - Second Edition by Peter Ries(6542)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(6313)